﻿import React from 'react';
import { Upload, Icon, message, Spin, Table, Button, Alert } from 'antd';
import {connect} from 'react-redux'
import {hashHistory} from 'react-router'
import './index.css'
import * as Util from '../../services/Util'
import AuthManager from '../../services/auth'
import { uploadDetailQuery } from '../../actions'

/**
 * 定义Header组件, 包括登录/注销的链接, 以及一些自定义链接
 */
class StudentImportDetail extends React.Component {

  constructor(props){
    super(props);
  }

  componentWillMount () {
    console.log('StudentImportDetail.componentWillMount')
    this.props.dispatch(uploadDetailQuery.request()({id:this.props.location.state.id}));
  }

  onBackClick(e) {
    e.preventDefault();
    hashHistory.goBack();
  }

  render() {

    const uploadDetailColumns = [
      {
        title: '行号',
        dataIndex: 'rowNum',
        width: '20%',
      },
      {
        title: '列号',
        dataIndex: 'cellNum',
        width: '20%',
      },
      {
        title: '状态',
        dataIndex: 'status',
        width: '20%',
        render:(text, record) => {
          if (record.status == '成功') {
            return (<span><Icon style={{color: '#87d068'}} type='check-circle' />&nbsp;{record.status}</span>);
          } else {
            return (<span><Icon style={{color: '#f50'}} type="close-circle" />&nbsp;{record.status}</span>);
          }

        } ,

      },
      {
        title: '失败原因',
        dataIndex: 'remark',
        width: '40%',
      },
    ];

    let { uploadDetails, loading=false } = this.props;

    return (
      <div style={{ marginTop: 16, minHeight: 560 }}>
        <div style={{ marginTop: 24, marginBottom: 16 }} className="clearfix">
            <Button type="primary" icon="arrow-left" onClick={this.onBackClick.bind(this)}>返回</Button>
        </div>
        <Spin spinning={loading}><Table columns={uploadDetailColumns} dataSource={uploadDetails} /></Spin>
      </div>
    );
  }

}

function mapStateToProps(state) {
  return {
    uploadDetails: state.upload.uploadDetails,
    loading: state.upload.loading,
  };
}

export default connect(mapStateToProps)(StudentImportDetail)
